package lzm.service;

import lzm.dao.StudentRepository;
import lzm.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service("studentService")
@Transactional
public class StudentServiceImpl implements IStudentService{
    @Autowired
    private StudentRepository studentRepository;


    public void updateName(String name, Long id) {
        studentRepository.updateName(name, id);
        //throw new RuntimeException("程序出现异常");
        System.out.println("更新成功");

    }

    public List<Student> queryAll() {
        return studentRepository.findAll();
    }

    public Student queryById(Long id) {
        return studentRepository.findById(id);
    }

    public void update(Student student) {
        studentRepository.save(student);
    }

    public void delete(Long id) {
        studentRepository.delete(id);
    }

    public void add(Student student) {
        studentRepository.save(student);
    }
}
